<?php


namespace app\api\controller\xiluedu;


use app\common\controller\Api;
use function fast\array_get;

class Article extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 文章列表
     * @throws \think\exception\DbException
     */
    public function lists(){
        $params = $this->request->param();
        $category_id = array_get($params,'category_id');
        if(!$category_id){
            $this->error('非法参数');
        }
        $pagisize = array_get($params,'pagesize',10);
        $lists = \app\common\model\xiluedu\Article::field('id,name,tags')
            ->where('category_id',$category_id)
            ->where('status','1')
            ->order('weigh','asc')
            ->paginate($pagisize);
        $this->success('查询成功',$lists);
    }

    /**
     * 文章详情
     * @throws \think\exception\DbException
     */
    public function detail(){
        $article_id = $this->request->param('article_id');
        if(!$article_id){
            $this->error('非法参数');
        }
        $row = \app\common\model\xiluedu\Article::field('thumb_image',true)->where('id',$article_id)
            ->find();
        $this->success('查询成功',$row);
    }
}